# -*- coding: UTF-8 -*-
"""
此类是用来识别字符串是什么语言的
"""
import langid


class Languagefunction:
    languagetotpi = {'en': 'LANGUAGEYY', 'cn': 'LANGUAGEZW', 'vi': 'LANGUAGEYNY', 'id': 'LANGUAGEYNIY',
                     'ms': 'LANGUAGEMLY', 'th': 'LANGUAGETY', 'lo': 'LANGUAGELWY', 'my': 'LANGUAGEMDY',
                     'km': 'LANGUAGEGMY'}

    def recongnizelanguage(self, torecognizedchar):
        try:
            languageS = langid.classify(torecognizedchar)
            language = languageS[0]
            languagetpi = self.languagetotpi[language]
            if not languagetpi:
                languagetpi = 'LANGUAGEYY'
            return languagetpi
        except Exception as e:
            print(str(e))
            return KeyError



